package com.af.security.mgt.account.register.token;

import org.hibernate.annotations.GenericGenerator;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.time.LocalDateTime;

/**
 * @author : zhenyun.su
 * @since : 2019/6/25
 * @common : 用户注册令牌， 用于在过期时间内激活用户
 */

@Entity
@Table(name="sys_user_register_token")
public class UserRegisterToken {
    @Id
    @GeneratedValue(generator = "UserRegisterToken")
    @GenericGenerator(name = "UserRegisterToken", strategy = "assigned")
    private String token;
    private Long userId;
    private LocalDateTime createdDate;
    private LocalDateTime expiryDate;
    private Boolean enabled;

    public UserRegisterToken() {
    }
    public UserRegisterToken(String token, Long userId) {
        this.token = token;
        this.userId = userId;
        this.createdDate = LocalDateTime.now();
        this.enabled=true;
    }

    public void calculateExpiryDate(int expiryTimeInHour) {
        this.expiryDate = LocalDateTime.now().plusHours(expiryTimeInHour);
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public LocalDateTime getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(LocalDateTime createdDate) {
        this.createdDate = createdDate;
    }

    public LocalDateTime getExpiryDate() {
        return expiryDate;
    }

    public void setExpiryDate(LocalDateTime expiryDate) {
        this.expiryDate = expiryDate;
    }

    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }
}
